{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8d9cc00d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1\n",
      "1    2\n",
      "2    3\n",
      "dtype: int64\n",
      "0    1\n",
      "1    a\n",
      "2    3\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 创建 Series 实例\n",
    "a = [1, 2, 3]\n",
    "\n",
    "myvar = pd.Series(a)\n",
    "\n",
    "print(myvar) # 索引、数据、数据类型\n",
    "a = [1, 'a', 3]\n",
    "myvar = pd.Series(a)\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "93997e8f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x    Google\n",
      "y    Runoob\n",
      "z      Wiki\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "# 修改索引值\n",
    "import pandas as pd\n",
    "\n",
    "a = [\"Google\", \"Runoob\", \"Wiki\"]\n",
    "\n",
    "myvar = pd.Series(a, index = [\"x\", \"y\", \"z\"])\n",
    "\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "674785a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    1\n",
      "1    2\n",
      "2    3\n",
      "dtype: int64\n",
      "1    Google\n",
      "2    Runoob\n",
      "3      Wiki\n",
      "dtype: object\n",
      "1    Google\n",
      "2    Runoob\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "# 示例1\n",
    "a = [1, 2, 3]\n",
    "myvar = pd.Series(a)\n",
    "print(myvar)\n",
    "\n",
    "\n",
    "# 示例2。使用 key/value 对象，类似字典来创建 Series\n",
    "sites = {1: \"Google\", 2: \"Runoob\", 3: \"Wiki\"}\n",
    "myvar = pd.Series(sites)\n",
    "print(myvar)\n",
    "\n",
    "\n",
    "# 示例3。字典中的部分数据\n",
    "sites = {1: \"Google\", 2: \"Runoob\", 3: \"Wiki\"}\n",
    "\n",
    "myvar = pd.Series(sites, index = [1, 2])\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "630da9fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1    Google\n",
      "2    Runoob\n",
      "Name: RUNOOB-Series-TEST, dtype: object\n"
     ]
    }
   ],
   "source": [
    "# 设置 Series 名称参数：\n",
    "sites = {1: \"Google\", 2: \"Runoob\", 3: \"Wiki\"}\n",
    "\n",
    "myvar = pd.Series(sites, index = [1, 2], name=\"RUNOOB-Series-TEST\" )\n",
    "\n",
    "print(myvar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ac7a2bf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
